<template>
  <!-- 已录入 -->
  <div class="box clearfix">
    <section class="section_wrap">
      <FunctionalAreas></FunctionalAreas>
      <div class="title_sub prduct_bod_r">产品说明：</div>
      <ProductDescriptionToo></ProductDescriptionToo>
    </section>
    <section class="section_wrap">
      <div class="title_sub infro_bod_l">信息查看：</div>
      <div class="state">状态：已录入</div>
      <InformationsViewer
        v-if="template === 'template_01'"
        :orderNumber="orderNumber"
        :showButton="showButton"
      ></InformationsViewer>
      <InformationsViewer02
        v-if="template === 'template_02'"
        :orderNumber="orderNumber"
        :reviewer="reviewer"
      ></InformationsViewer02>
    </section>
    <section class="section_wrap" v-if="showFinancialInfo ">
      <div class="title_sub infro_bod_l">财务信息：</div>
      <financialInfo :showBtn="showBtn" :orderNumber="orderNumber"></financialInfo>
    </section>
    <section class="section_wrap">
      <div class="title_sub infro_bod_l">风控大数据查询</div>
      <viewInfo></viewInfo>
    </section>
    <section class="section_wrap" v-if="showChannelSign">
      <div class="title_sub upload_bod_l">签约：</div>
      <ChannelSign :orderNumber="orderNumber"></ChannelSign>
    </section>
    <section class="section_wrap">
      <div class="title_sub upload_bod_l">附件管理：</div>
      <!-- 上传组件 -->
      <Upload ref="Uploade" :isNew="isNew"></Upload>
    </section>
    <section class="section_wrap">
      <Attachment></Attachment>
      <div>
        <el-button
          type="primary"
          class="primaryButton"
          @click="primaryButton"
          v-if="showOrderCommit"
        >提交审批
        </el-button
        >
      </div>
      <div class="title_sub infro_bod_l">操作记录：</div>
      <OperationRecords :orderNumber="orderNumber"></OperationRecords>
    </section>
  </div>
</template>

<script>
import {
  putOrderCommit,
  getProductUrl,
  getOrderOne
} from "../../../src/assets/js/api";
import FunctionalAreas from "../../components/business/FunctionalAreas";
import ProductDescriptionToo from "../../components/business/ProductDescriptionToo";
import InformationsViewer from "../../components/business/InformationsViewer";
import InformationsViewer02 from "../../components/business/InformationsViewer02";
import Attachment from "../../components/business/Attachment";
import Upload from "../../components/business/Upload";
import ChannelSign from "../../components/signUp/ChannelSign";
import viewInfo from "../../components/business/viweInfo.vue";

import OperationRecords from "../../components/business/OperationRecords";
import { checkPermiss } from "../../assets/js/utlis";
import financialInfo from "../../components/business/financialInfo";

export default {
  name: "HasBeenRecorded",
  components: {
    FunctionalAreas,
    ProductDescriptionToo,
    InformationsViewer,
    InformationsViewer02,
    Attachment,
    Upload,
    ChannelSign,
    OperationRecords,
    viewInfo,
    financialInfo
  },
  data() {
    return {
      //TODO
      showChannelSign: false,
      showButton: true,
      isNew: false,
      orderNumber: "",
      markUpdate: "",
      golbalPermissions: [],
      ProductUrl: "",
      template: "",
      prductId: "",
      reviewer: null //判断是否是审件专员!
    };
  },
  /*
 安居分 产品id: 4
 乐业保 产品id: 3
 贵州安居分 产品id: 6
 担保安居分 产品id: 15

 * */
  created() {
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.prductId = parseInt(sessionStorage.getItem("prductId"));
    this.getOrderNum();
    this.getProductUrl();
    this.getOrderOne(this.prductId);
    this.stateNODE_ENV = process.env.NODE_ENV.trim().toLowerCase();
  },
  computed: {
    //财务信息按钮显示
    showBtn: function() {
      if (this.prductId == 3) {
        return checkPermiss("business:updateFinancial:lyb", this.golbalPermissions);
      }
      if (this.stateNODE_ENV == "development") {
        //开发环境
        if (this.prductId == 15) {
          //担保安居分
          return checkPermiss("business:updateFinancial:db", this.golbalPermissions);
        } else {
          return false;
        }
      } else {
        //生产环境
        if (this.prductId == 13) {
          //担保安居分
          return checkPermiss("business:updateFinancial:db", this.golbalPermissions);
        } else {
          return false;
        }
      }

    },
    //财务信息
    showFinancialInfo: function() {
      if (this.prductId == 3) {
        //乐业保
        return checkPermiss("business:upForm:financial:lyb", this.golbalPermissions);
      }
      if (this.stateNODE_ENV == "development") {
        if (this.prductId == 15) {
          //担保安居分
          return checkPermiss("business:upForm:financial:db", this.golbalPermissions);
        } else {
          return false;
        }

      } else {
        if (this.prductId == 13) {
          //担保安居分
          return checkPermiss("business:upForm:financial:db", this.golbalPermissions);
        } else {
          return false;
        }
      }
    }
    ,
      //提交审批按钮
      showOrderCommit: function() {
        return checkPermiss("business:order:commit", this.golbalPermissions);
      }
    },
    methods: {
      getOrderOne(id) {
        getOrderOne(id).then((res) => {
          this.template = res.data.pcCode;
        });
      },
      //根据orderNumber判断跳转的产品路径
      getProductUrl() {
        getProductUrl({ orderNumber: this.orderNumber }).then((res) => {
          // sessionStorage.setItem("reviewer", res.data.reviewer);
          this.reviewer = sessionStorage.getItem("reviewer");
          this.ProductUrl = res.data.productUrl;
        });
      },
      //判断获取orderNumber
      getOrderNum() {
        let orderNumber = this.$route.query.orderNumber;
        if (orderNumber) {
          this.orderNumber = orderNumber;
        } else {
          this.orderNumber = sessionStorage.getItem("orderNumber");
        }
      },
      //提交审批按钮
      primaryButton() {

        //验证审批的身份证图片
        let accList = this.$refs.Uploade.accList;
        var idStatus = false;
        if (
          accList.type1face.data.length > 0 &&
          accList.type1back.data.length > 0
        ) {
          idStatus = true;
        }
        /*var faceStatus = false;
        var backStatus = false;
        for (const item of accList) {
          if(faceStatus && backStatus){
            break;
          }
          for(let key in item){
            if(key=="tpye1face" && accList[key].length>0){
              faceStatus = true;
            }
            if(key=="tpye1face" && accList[key].length>0){
              backStatus = true;
            }
          }
        }*/
        if (!idStatus) {
          this.$message({
            message: "请上传身份证件照",
            type: "error"
          });
        } else {
          putOrderCommit(this.orderNumber).then((res) => {
            this.$message({
              message: res.message,
              type: "success"
            });
            this.$router.replace({ path: this.ProductUrl });
          });
        }
      }
    }
  };
</script>

<style scoped type="less">
.text {
  font-size: 20px;
  font-weight: bold;
  margin-top: 20px;
  text-align: left;
  text-indent: 2em;
}

.state {
  font-size: 22px;
  font-weight: bold;
  float: right;
  margin-top: -20px;
  margin-right: 3%;
}

.uploadStyle {
  position: relative;

  width: 97%;
  margin-top: 20px;
}

.primaryButton {
  width: 180px;
  height: 45px;
  margin-top: 20px;
}

</style>
